package nicg.st.util;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author GeChen
 * @Description
 * @date 2019/11/3 23:20
 */
public class DecodeMatrix {
    public static double[][] DecodeMatrix(String matrix) {
        String length = matrix.substring(0, 1);
        int len = Integer.parseInt(length);
        double[][] result = new double[len][len];
        Queue<Double> list = new LinkedList<>();
        for (int i = 2; i < matrix.length(); i++) {
            String res = "";
            while (matrix.charAt(i) != ' ' && matrix.charAt(i) != ']' && i < matrix.length()) {
                res = res + matrix.charAt(i);
                i++;
            }
            Double sim = Double.parseDouble(res);
            list.add(sim);
        }
        for (int i = 0; i < len; i++) {
            for (int j = 0; j < len; j++) {
                result[i][j] = list.poll();
            }
        }
        return result;
    }
}
